]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st/texture-cache: Always close GdkPixbufLoader before disposal
authorBarnabás Pőcze <pobrn@protonmail.com>
Sun, 5 Nov 2023 01:49:34 +0000 (02:49 +0100)
committerBarnabás Pőcze <pobrn@protonmail.com>
Sun, 5 Nov 2023 02:29:12 +0000 (03:29 +0100)
As per the warning emitted when destroying without closing first

  GdkPixbufLoader finalized without calling gdk_pixbuf_loader_close() - this is not allowed.
  You must explicitly end the data stream to the loader before dropping the last reference.

closing it is necessary.

Create the GdkPixbufLoader after loading the file contents so that
the loader is guaranteed to be closed before it is destroyed.
(`gdk_pixbuf_loader_write()` closes it on failure.)

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3008>

src/st/st-texture-cache.c

index 2986f5bb3493703de44e5f412b2fa2e89e406bf8..8d773dabb7cba3245b324268c21697b30295f2be 100644 (file)
@@ -1381,7 +1381,7 @@ load_sliced_image (GTask        *result,
   GdkPixbuf *pix;
   gint width, height, y, x;
   gint scale_factor;
-  GdkPixbufLoader *loader;
+  GdkPixbufLoader *loader = NULL;
   GError *error = NULL;
   gchar *buffer = NULL;
   gsize length;
@@ -1391,15 +1391,15 @@ load_sliced_image (GTask        *result,
   data = task_data;
   g_assert (data);
 
-  loader = gdk_pixbuf_loader_new ();
-  g_signal_connect (loader, "size-prepared", G_CALLBACK (on_loader_size_prepared), data);
-
   if (!g_file_load_contents (data->gfile, cancellable, &buffer, &length, NULL, &error))
     {
       g_warning ("Failed to open sliced image: %s", error->message);
       goto out;
     }
 
+  loader = gdk_pixbuf_loader_new ();
+  g_signal_connect (loader, "size-prepared", G_CALLBACK (on_loader_size_prepared), data);
+
   if (!gdk_pixbuf_loader_write (loader, (const guchar *) buffer, length, &error))
     {
       g_warning ("Failed to load image: %s", error->message);
@@ -1428,7 +1428,7 @@ load_sliced_image (GTask        *result,
  out:
   /* We don't need the original pixbuf anymore, which is owned by the loader,
    * though the subpixbufs will hold a reference. */
-  g_object_unref (loader);
+  g_clear_object (&loader);
   g_free (buffer);
   g_clear_pointer (&error, g_error_free);
   g_task_return_pointer (result, res, free_glist_unref_gobjects);